package weaver.interfaces.jjy.duss.action;

import com.weaver.general.BaseBean;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.interfaces.jjy.duss.hr.ZFM_HR_BZ_ZGJG_B;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

import java.util.HashMap;
import java.util.Map;

/**
 * @Title: ecology-9-demo
 * @Company: 泛微软件
 * @author: weaver.Dusongsong
 * @version: 1.0
 * @CreateDate: 2020-05-09
 * @Description: 主管架构调整推送SAP
 * @ModifyLog:
 **/

public class WeaZgjgtztsAction extends BaseBean implements Action {
    @Override
    public String execute(RequestInfo requestInfo) {
        RecordSet rs = new RecordSet();
        weaver.general.BaseBean baseBean = new weaver.general.BaseBean();
        String requestid = requestInfo.getRequestid();
        baseBean.writeLog("请求ID" + requestid);
        baseBean.writeLog("调用WeaZgjgtztsAction");
        String tablename = requestInfo.getRequestManager().getBillTableName();//主表
        rs.executeQuery("select zehr_bmbm,zehr_mbxl,zehr_fsrq from " + tablename + " where requestid=?", requestid);
        baseBean.writeLog("select zehr_bmbm,zehr_mbxl,zehr_fsrq from " + tablename + " where requestid=" + requestid);
        rs.next();
        //主表字段
        String zehr_bmbm = Util.null2String(rs.getString("zehr_bmbm"));//部门ID
        String zehr_mbxl = Util.null2String(rs.getString("zehr_mbxl"));//模板序列
        String zehr_fsrq = Util.null2String(rs.getString("zehr_fsrq").replaceAll("-", ""));//发送日期
        Map<String,String> map = new HashMap<>();
        map.put("IV_BMBM",zehr_bmbm);//部门ID
        map.put("IV_DATUM",zehr_fsrq);//发送日期
        map.put("IV_MBXL",zehr_mbxl);//模板序列
        map.put("IV_NUMID",requestid);//OA主键
        baseBean.writeLog("WeaZgjgtztsAction参数"+map.toString());
        try {
            ZFM_HR_BZ_ZGJG_B bz_zgjg_b = new ZFM_HR_BZ_ZGJG_B();
            Map resultMap = bz_zgjg_b.execute(map);
            String flag = Util.null2String(resultMap.get("ZFLAG"));
            String message = Util.null2String(resultMap.get("ZMESG"));
            baseBean.writeLog("SAP返回结果——flag:" + flag + ";message:" + message);
            if ("E".equalsIgnoreCase(flag)) {
                requestInfo.getRequestManager().setMessageid("111111");
                requestInfo.getRequestManager().setMessagecontent("SAP返回信息提示:"+message);
                return Action.FAILURE_AND_CONTINUE;
            }
            return Action.SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            baseBean.writeLog("异常参考:" + e);
            requestInfo.getRequestManager().setMessageid("111111");
            requestInfo.getRequestManager().setMessagecontent(e.getMessage());
            return Action.FAILURE_AND_CONTINUE;
        }
    }
}
